#define _CRT_SECURE_NO_WARNINGS 1

#include<iostream>
#include<queue>

using namespace std;

struct TreeNode
{
	int val;
	TreeNode* left;
	TreeNode* right;
};

bool isfullTree(TreeNode * p)
{
	if (p == NULL)return true;
	//Judging the number of layers and nodes if a Binary Tree
	queue<TreeNode*>help;
	help.push(p);
	TreeNode* end = p;
	TreeNode* next = NULL;
	int numNodes = 0;
	int numLayers = 0;
	while (!help.empty()) {
		p = help.front();
		help.pop();
		numNodes++;
		if (p->left != NULL) 
		{
			help.push(p->left);
				next = p->left;
		}
		if (p->right != NULL) {
			help.push(p->right);
			next = p->right;
		}
		if (p == end) {
			end = next;
			next = NULL;
			numLayers++;
		}
	}
	if (numNodes == pow(2, numLayers) - 1)
		return true;
	else
		return false;

}